@(cart: Cart, gateways: List[Gateway])(implicit flash: Flash, request: RequestHeader, user: Option[User])

  <div class="cart-total">
    <table>
      @for(total <- cart.totals) {
      <tr>
        <td>@Messages(total._1):</td>
        <td>@Messages("format_price", total._2)</td>
      </tr>
      }
    </table>
  </div>
  <div class="cart-details">
    <table width="100%">
      <tr>
        <td>Способ оплаты:</td>
        <td><select id="payment" class="box">
          @for(gateway <- gateways if cart.shipment != "download" || !gateway.categories.contains("ondelivery")) {
          <option value="@gateway.name" category="@{"\\w+".r.findAllIn(gateway.categories).toSeq.head}" @if(cart.payment == gateway.name) {selected="true"}>@Messages("pgw_" + gateway.name)</option>
          }
          </select></td>
      </tr>
      <tr>
        <td>Способ доставки:</td>
        <td><select id="shipment" class="box">
          @for(shipment <- List("download", "ship")) { <!-- TODO: ship to RU only -->
            <option value="@shipment" @if(cart.shipment == shipment) {selected="true"}>@Messages("shipment_" + shipment)</option>
          }
        </select>
        </td>
      </tr>
      @if(cart.shipment != "download" || !user) {
        <tr>
          <td colspan="2"></td>
        </tr>
        @user.map { user =>
        <tr>
          <td>Адрес доставки:</td>
          @user.address.map { address =>
          <td>@user.firstname @user.lastname</td>
        </tr>
        <tr>
            <td><a class="dialog" style="float: right; padding-right: 20px">Изменить</a></td>
          <td>@address.address_1</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>@address.city</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>@address.zone</td>
        </tr>
        <tr>
          <td></td>
          <td>@address.country @address.postcode</td>
          }
          @if(!user.address) {
          <td><a class="dialog">Ввести</a></td>
          }
        </tr>
        }
        @if(!user) {
        <tr>
          <td colspan="2">@Html(Messages("text_welcome",
            routes.Account.login + "?returnUrl=" + Application.encodeUrl(routes.Checkout.checkout.url),
            routes.Account.register + "?returnUrl=" + Application.encodeUrl(routes.Checkout.checkout.url)))</td>
        </tr>
        }
      }
    </table>
  </div>

<script type="text/javascript">
$('select#payment').change(function() {
  var payment = $(this).val();
  var category = $("option:selected", this).attr("category");
  return updateCart(jsRoutes.controllers.Checkout.updatePayment().ajax, {gateway: payment, _category: category}, function() {
  })
});

$('select#shipment').change(function() {
  var shipment = $(this).val();
  return updateCart(jsRoutes.controllers.Checkout.updateShipment().ajax, {shipment: shipment}, function() {
  })
});

$('a.dialog').click(function() {
  $('#dialog').dialog('open');
}); 
</script>

